using NodeCanvas.Variables;
using UnityEngine;

namespace NodeCanvas.Actions
{
	[Category("Physics")]
	[AgentType(typeof(Transform))]
	public class GetLinecastInfo2D : ActionTask
	{
		[RequiredField]
		public BBGameObject target;

		public LayerMask mask = -1;

		[BlackboardOnly]
		public BBGameObject saveHitGameObjectAs;

		[BlackboardOnly]
		public BBFloat saveDistanceAs;

		[BlackboardOnly]
		public BBVector savePointAs;

		[BlackboardOnly]
		public BBVector saveNormalAs;

		protected override void OnExecute()
		{
			RaycastHit2D raycastHit2D = Physics2D.Linecast(base.agent.transform.position, target.value.transform.position, mask);
			if (raycastHit2D.collider != null)
			{
				saveHitGameObjectAs.value = raycastHit2D.collider.gameObject;
				saveDistanceAs.value = raycastHit2D.fraction;
				savePointAs.value = raycastHit2D.point;
				saveNormalAs.value = raycastHit2D.normal;
				EndAction(true);
			}
			else
			{
				EndAction(false);
			}
		}

		protected override void OnGizmosSelected()
		{
			if ((bool)base.agent && (bool)target.value)
			{
				Gizmos.DrawLine(base.agent.transform.position, target.value.transform.position);
			}
		}
	}
}
